﻿module Sustainalytics.GCCS {

    import Common = Sustainalytics.Common;

    export class GCOverallCompanySummaryService implements IGCOverallCompanySummaryService {

        constructor(
            private $q: ng.IQService,
            private $http: ng.IHttpService,
            private notificationFactory: Common.INotificationFactory,
            private staticObjects: Common.IStaticObjects) {
        }

        // get overall company summary by company ID
        public GetByCompany(companyId: string, overallAssessment?: GCAssessment): ng.IPromise<GCOverallCompanySummaryDto> {
            var def = this.$q.defer();

            var args = $.param(
                {
                    companyId: companyId,
                    overallAssessment: overallAssessment
                });

            var httpPromise: ng.IHttpPromise<GCOverallCompanySummaryDto> = this.$http.get('/gccsserv/api/v1/gcoverallcompanysummary?' + args);

            httpPromise
                .success(function (data) {
                    def.resolve(data);
                })
                .error(function (data, status, headers, config) {
                    def.reject({ data: data, status: status, headers: headers, config: config });
                });

            return def.promise;
        }
    }


    // register service with angular
    angular.module('Sustainalytics.GCCS').factory('GCOverallCompanySummaryService',
        ($q: ng.IQService, $http: ng.IHttpService, notificationFactory: Common.INotificationFactory, staticObjects: Common.IStaticObjects) => {
            var service = new GCOverallCompanySummaryService($q, $http, notificationFactory, staticObjects);
            return service;
        });
}